resource map
Resource File Format Definition of resource file structure.
Writing programs that modify resource files directly requires that you know
exactly what a resource file consists of.
The resource header is a 16-byte block that gives the offsets to and lengths of
the resource-data and resource-map parts of the file. It contains: 4 bytes that tell
the offset from the beginning of the resource file to the resource data; 4 bytes that
indicate the offset from the beginning of the resource file to the resource map; 4
bytes that tell the length of the resource data; and 4 bytes that list the length of the
resource map.
The next 112 bytes are reserved for system use and the 128 bytes that come next
are reserved for the Resource Manager. These 128 bytes are labeled " available
for application data" in Inside Macintosh Volume 1, but Macintosh Technical Note
#62 states that they are reserved by the Resource Manager.
Next in the resource header come 4 bytes that tell the length of the resource
data, which follows immediately and whose size is variable.
The final component of the resource header is the resource map, which starts
out with three reserved areas: 16 bytes for a copy of the resource header; 4 bytes
for a handle to the next resource map; and 2 bytes for a file reference
number. The resource map also contains 2 bytes describing the resource file's
attributes; 2 bytes to show the offset from the beginning of the resource map
to the type list; and 2 bytes to indicate the offset to the resource name list
(see diagram below).
Once the Resource Manager reads the resource map, it uses the reserved
areas at the beginning of the header to store the indicated information from the
map.
The type list has a 2-byte block that shows the total number of resource
types in the map, minus 1. It also contains 4 bytes to describe the resource type,
2 bytes showing the number of resources of this type (minus 1) that the map
contains; and 2 bytes to show the offset from the beginning of the type list to the
reference list for this type of resource.
The reference list holds the resource references for all resources of that type .
Reference lists are placed one after an other, in their order of appearance on the
type lists. Each reference list consists of: 2 bytes of Resource ID; 2 bytes
showing the offset from the beginning of the resource name list to the length of
the resource name (-1 if none); 1 byte showing resource attributes; 3 bytes
with information on the offset from the beginning of the resource data to the length
of the data for this resource; and 4 bytes of reserved space for a handle to the
resource.
Lastly, the resource file contains a resource name list that has a 1-byte indicator
showing the length of the resource name and a variable number of bytes holding the
characters of the resource's name. The following diagram shows the relation of
resource file elements.
Remember that parts of the system ( including the File Manager and the Finder)
assume that if the resource fork exists, it will contain valid Resource Manager
information. For this reason, it is important to avoid using the resource fork for
non-resource data. Apple provides the call PBOpenRF to let you copy the resource
fork of a file without it being interpreted by the Resource Manager, but this
function is not intended to be used to open "another data fork". The File Manager
assumes that the first block of the file's resource fork will be part of the resource
header, and puts information there to aid in scavenging. This means that one copy of
a resource file opened with PBOpenRF may not be exactly the same as the original.